﻿@model SimpleIdServer.IdServer.UI.ViewModels.AuthenticatePasswordViewModel
@using SimpleIdServer.IdServer.Startup.Resources

@{
    ViewBag.Title = AuthenticatePasswordResource.title;
    Layout = "~/Views/Shared/_AuthenticateLayout.cshtml";
}

@if (!ViewData.ModelState.IsValid)
{
    <ul class="list-group">
        @foreach (var modelState in ViewData.ModelState.Values)
        {
            foreach (var error in modelState.Errors)
            {
                <li class="list-group-item list-group-item-danger">@AuthenticatePasswordResource.ResourceManager.GetString(error.ErrorMessage)</li>
            }
        }
    </ul>
}

@if (Model.IsLoginMissing)
{
    <div class="alert alert-danger">
        @AuthenticatePasswordResource.missing_login
    </div>
}
else
{
    @using (Html.BeginForm("Index", "Authenticate", new { area = SimpleIdServer.IdServer.Constants.Areas.Password, returnUrl = Model.ReturnUrl }, FormMethod.Post))
    {
        @Html.AntiForgeryToken()
        <input type="hidden" value="@Model.ReturnUrl" name="ReturnUrl" />
        <div class="alert alert-info">
            Default credentials :
            <p style="margin: 0px;">
                <b>Login: </b>administrator<br />
                <b>Password: </b>password
            </p>
        </div>
        <!-- Login -->
        <div class="input-group mb-3">
            @if (Model.IsAuthInProgress)
            {
                <input asp-for="Login" placeholder="@AuthenticatePasswordResource.login" type="text" class="form-control" disabled="disabled" />
                <input asp-for="Login" placeholder="@AuthenticatePasswordResource.login" type="hidden" class="form-control" />
            }
            else
            {
                <input asp-for="Login" placeholder="@AuthenticatePasswordResource.login" type="text" class="form-control" />
            }
        </div>
        <!-- Password -->
        <div class="input-group mb-3">
            <input type="password" value="@Model.Password" name="Password" class="form-control" placeholder="@AuthenticatePasswordResource.password">
        </div>
        <div>
            <input type="checkbox" value="@Model.RememberLogin" name="RememberLogin" />
            <label>@AuthenticatePasswordResource.remember_login</label>
        </div>

        <input asp-for="IsLoginMissing" type="hidden" class="form-control" />
        <input asp-for="IsAuthInProgress" type="hidden" class="form-control" />
        <button type="submit" class="btn btn-primary">@AuthenticatePasswordResource.submit</button>
    }
}

@section SubScripts {
    <script type="text/javascript">
        $(document).ready(function () {
            $(".login input[name='RememberLogin']").change(function (e) {
                $(this).val($(this).is(':checked'));
            });
        });
    </script>
}